package com.hbnu.system.controller;


import com.hbnu.system.core.base.CommonPage;
import com.hbnu.system.core.base.Rest;
import com.hbnu.system.model.dto.CheckBackDTO;
import com.hbnu.system.model.dto.PorProjectTSdto;
import com.hbnu.system.model.dto.Porproject_registrationDTO;
import com.hbnu.system.model.entity.Porproject_registration;
import com.hbnu.system.model.entity.Porprojectfile;
import com.hbnu.system.model.query.PorProjectExportQuery;
import com.hbnu.system.model.query.PorProjectPageQuery;
import com.hbnu.system.model.vo.ExportPorProjectVO;
import com.hbnu.system.service.IPorproject_registrationService;
import com.hbnu.system.service.PorprojectfileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2023-05-16
 */
@RestController
@RequestMapping("/porproject_registration")
@Api(tags = "纵向项目模块")
public class Porproject_registrationController {
    @Autowired
    IPorproject_registrationService iPorproject_registrationService;

    @Autowired
    PorprojectfileService porprojectfileService;
    @ApiOperation("纵向项目-录入")
    @PostMapping("/AddZXProject")
    public Rest<Boolean> AddZXProject(@RequestBody @Valid Porproject_registrationDTO porProjectRegistrationDTO){
        boolean add = iPorproject_registrationService.addPorproject(porProjectRegistrationDTO);
        return add ? Rest.success() : Rest.failed();
    }

    @ApiOperation("纵向项目-删除")
    @GetMapping("/DeleteZXProject")
    public Rest<Boolean> DeleteZXProject(String pregistrationID) throws IOException {
        boolean delete = iPorproject_registrationService.deletePorproject(pregistrationID);
        return delete ? Rest.success() : Rest.failed();
    }

    @ApiOperation("纵向项目-修改")
    @PostMapping("/UpdateZXProject")
    public Rest<Boolean> UpdateZXProject(@RequestBody @Valid Porproject_registrationDTO porProjectRegistrationDTO){
        boolean update = iPorproject_registrationService.updatePorproject(porProjectRegistrationDTO);
        return update ? Rest.success() : Rest.failed();
    }

    @ApiOperation("根据主键纵向项目DTO查询")
    @GetMapping("/GetZxProjectDTOById")
    public Rest<Porproject_registrationDTO> GetHxProjectDTOById(String projectID){
        Porproject_registrationDTO tranprojectdto = iPorproject_registrationService.getPorprojectDTOById(projectID);
        return Rest.success(tranprojectdto);
    }

    @ApiOperation("纵向项目在研申请-提交")
    @GetMapping("/CommitZXProject")
    public Rest<Boolean> CommitZXProject(String tranprojectID){
        Boolean commit = iPorproject_registrationService.CommitPorproject(tranprojectID);
        return commit ? Rest.success() : Rest.failed();
    }

    @ApiOperation("纵向项目在研-院级通过")
    @GetMapping("/CollegePassZXProject")
    public Rest<String> CollegePassZXProject(@RequestHeader("X-Token") String token, String tranprojectID){
        Boolean b = iPorproject_registrationService.collegeCheckPass(token, tranprojectID);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("纵向项目在研-院级退回")
    @PostMapping("/CollegeBackZXProject")
    public Rest<String> CollegeBackZXProject(@RequestHeader("X-Token") String token, @RequestBody CheckBackDTO checkBackDTO){
        Boolean b = iPorproject_registrationService.collegeCheckBack(token, checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("纵向项目结题-提交")
    @GetMapping("/CommitFinishZXProject")
    public Rest<Boolean> CommitFinishZXProject(String tranprojectID){
        Boolean commit = iPorproject_registrationService.CommitPorprojectFinish(tranprojectID);
        return commit ? Rest.success() : Rest.failed();
    }

    @ApiOperation("纵向项目结题-院级通过")
    @GetMapping("/CollegeFinishPassZXProject")
    public Rest<String> CollegeFinishPassZXProject(@RequestHeader("X-Token") String token, String tranprojectID){
        Boolean b = iPorproject_registrationService.collegeFinishCheckPass(token, tranprojectID);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("纵向项目结题-院级退回")
    @PostMapping("/CollegeFinishBackZXProject")
    public Rest<String> CollegeFinishBackZXProject(@RequestHeader("X-Token") String token, @RequestBody CheckBackDTO checkBackDTO){
        Boolean b = iPorproject_registrationService.collegeFinishCheckBack(token, checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("纵向项目在研-校级通过")
    @GetMapping("/SchoolPassZXProject")
    public Rest<String> SchoolPassZXProject(@RequestHeader("X-Token") String token,String tranprojectID){
        Boolean b = iPorproject_registrationService.schoolCheckPass(token,tranprojectID);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("纵向项目在研-校级退回")
    @PostMapping("/SchoolBackZXProject")
    public Rest<String> ZXSchoolBackIdentify(@RequestHeader("X-Token") String token,@RequestBody CheckBackDTO checkBackDTO){
        Boolean b = iPorproject_registrationService.schoolCheckBack(token,checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("纵向项目结题-校级通过")
    @GetMapping("/SchoolFinishPassZXProject")
    public Rest<String> SchoolFinishPassZXProject(@RequestHeader("X-Token") String token,String tranprojectID){
        Boolean b = iPorproject_registrationService.schoolFinishCheckPass(token,tranprojectID);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("纵向项目结题-校级退回")
    @PostMapping("/SchooFinishlBackZXProject")
    public Rest<String> SchooFinishlBackZXProject(@RequestHeader("X-Token") String token,@RequestBody CheckBackDTO checkBackDTO){
        Boolean b = iPorproject_registrationService.schoolFinishCheckBack(token,checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }


    @ApiOperation("用户获取自身项目-分页——产学合作育人")
    @PostMapping("/userGetProjects")
    public Rest<CommonPage<Porproject_registration>> userGetProjects(@RequestBody PorProjectPageQuery porProjectPageQuery){
        CommonPage<Porproject_registration> tranprojectRegistrationCommonPage = iPorproject_registrationService.userGetProjects(porProjectPageQuery);
        return Rest.success(tranprojectRegistrationCommonPage);
    }


    @ApiOperation("纵向项目导出")
    @PostMapping("/export")
    public Rest<CommonPage<Porproject_registration>> export(@RequestBody PorProjectPageQuery porProjectPageQuery){
        CommonPage<Porproject_registration> tranprojectRegistrationCommonPage = iPorproject_registrationService.export(porProjectPageQuery);
        return Rest.success(tranprojectRegistrationCommonPage);
    }

    @ApiOperation("纵向项目导出文件——最新版")
    @PostMapping("/exportPorProject")
    public Rest<List<ExportPorProjectVO>> exportPorProject(@RequestBody PorProjectExportQuery porProjectExportQuery){
        List<ExportPorProjectVO> exportPorProjectVOList = iPorproject_registrationService.exportPorProject(porProjectExportQuery);
        return Rest.success(exportPorProjectVOList);
    }
    
    @ApiOperation("暂存纵向项目数据")
    @PostMapping("/saveDraftProject")
    public Rest<Boolean> saveDraftProject(@RequestBody PorProjectTSdto porProjectTSdto){
        boolean result = iPorproject_registrationService.saveDraftProject(porProjectTSdto);
        return result ? Rest.success() : Rest.failed();
    }


    @ApiOperation("纵向项目-文件信息上传")
    @PostMapping("/addZXprojectfile")
    public Rest<Boolean> addZXprojectfile(@RequestBody Porprojectfile porprojectfile){
        boolean add = porprojectfileService.addPorprojectfile(porprojectfile);
        return add ? Rest.success() : Rest.failed();
    }
    @ApiOperation("纵向项目-文件信息删除")
    @GetMapping("/DeleteZXprojectfile")
    public Rest<Boolean> DeleteZXprojectfile(String id)throws IOException {
        boolean delete = porprojectfileService.deletPorprojectfile(id);
        return delete ? Rest.success() : Rest.failed();
    }
    @ApiOperation("纵向项目-文件信息分页查询")
    @GetMapping ("/pageZXprojectfileCondition")
    public Rest<List<Porprojectfile>> pageZXprojectfileConditionfile(String id){
        List<Porprojectfile> page = porprojectfileService.pagePorprojectfile(id);
        return Rest.success(page);
    }
    @ApiOperation("纵向项目-文件信息修改")
    @PostMapping("/updateZXprojectfile")
    public Rest<Boolean> updateZXprojectfile(@RequestBody Porprojectfile porprojectfile){
        boolean update = porprojectfileService.updatePorprojectfile(porprojectfile);
        return update ? Rest.success() : Rest.failed();
    }

    @ApiOperation("纵向项目撤回")
    @GetMapping("/WithdrawZXProject")
    public Rest<Boolean> WithdrawZXProject(@RequestHeader("X-Token") String token, String porprojectID){
        Boolean withdraw = iPorproject_registrationService.withdrawZXProject(token, porprojectID);
        return withdraw ? Rest.success() : Rest.failed();
    }

}

